home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INSTALL / program files / Borland / Delphi6 / Doc / Dialogs.int < prev    next >
Encoding:
Text File  |  2001-05-22  |  9.3 KB  |  275 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {  Copyright (c) 1995-2001 Borland Software Corporation }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit Dialogs;
  11.  
  12. {$R-,T-,H+,X+}
  13.  
  14. interface
  15.  
  16. uses Windows, Messages, SysUtils, CommDlg, Classes, Graphics, Controls,
  17.   Forms, StdCtrls, Printers;
  18.  
  19. const
  20.  
  21. { Maximum number of custom colors in color dialog }
  22.  
  23.   MaxCustomColors = 16;
  24.  
  25. type
  26.  
  27. { TCommonDialog }
  28.  
  29.   TCommonDialog = class(TComponent)
  30.   protected
  31.     procedure DoClose; dynamic;
  32.     procedure DoShow; dynamic;
  33.     procedure WndProc(var Message: TMessage); virtual;
  34.     function MessageHook(var Msg: TMessage): Boolean; virtual;
  35.     function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; virtual;
  36.     property Template: PChar;
  37.   public
  38.     constructor Create(AOwner: TComponent); override;
  39.     destructor Destroy; override;
  40.     function Execute: Boolean; virtual; abstract;
  41.     procedure DefaultHandler(var Message); override;
  42.     property Handle: HWnd;
  43.   published
  44.     property Ctl3D: Boolean default True;
  45.     property HelpContext: THelpContext default 0;
  46.     property OnClose: TNotifyEvent;
  47.     property OnShow: TNotifyEvent;
  48.   end;
  49.  
  50. { TOpenDialog }
  51.  
  52.   TOpenOption = (ofReadOnly, ofOverwritePrompt, ofHideReadOnly,
  53.     ofNoChangeDir, ofShowHelp, ofNoValidate, ofAllowMultiSelect,
  54.     ofExtensionDifferent, ofPathMustExist, ofFileMustExist, ofCreatePrompt,
  55.     ofShareAware, ofNoReadOnlyReturn, ofNoTestFileCreate, ofNoNetworkButton,
  56.     ofNoLongNames, ofOldStyleDialog, ofNoDereferenceLinks, ofEnableIncludeNotify,
  57.     ofEnableSizing, ofDontAddToRecent, ofForceShowHidden);
  58.   TOpenOptions = set of TOpenOption;
  59.  
  60.   TOpenOptionEx = (ofExNoPlacesBar);
  61.   TOpenOptionsEx = set of TOpenOptionEx;
  62.  
  63.   TFileEditStyle = (fsEdit, fsComboBox);
  64.   TOFNotifyEx = type CommDlg.TOFNotifyEx;
  65.   {$NODEFINE TOFNotifyEx}
  66.   TIncludeItemEvent = procedure (const OFN: TOFNotifyEx; var Include: Boolean) of object;
  67.  
  68.   TOpenDialog = class(TCommonDialog)
  69.   protected
  70.     function CanClose(var OpenFileName: TOpenFileName): Boolean;
  71.     function DoCanClose: Boolean; dynamic;
  72.     function DoExecute(Func: Pointer): Bool;
  73.     procedure DoSelectionChange; dynamic;
  74.     procedure DoFolderChange; dynamic;
  75.     procedure DoTypeChange; dynamic;
  76.     procedure DoIncludeItem(const OFN: TOFNotifyEx; var Include: Boolean); dynamic;
  77.     procedure DefineProperties(Filer: TFiler); override;
  78.     procedure GetFileNames(var OpenFileName: TOpenFileName);
  79.     function GetStaticRect: TRect; virtual;
  80.     procedure WndProc(var Message: TMessage); override;
  81.   public
  82.     constructor Create(AOwner: TComponent); override;
  83.     destructor Destroy; override;
  84.     function Execute: Boolean; override;
  85.     property FileEditStyle: TFileEditStyle;
  86.     property Files: TStrings;
  87.     property HistoryList: TStrings;
  88.   published
  89.     property DefaultExt: string;
  90.     property FileName: TFileName;
  91.     property Filter: string;
  92.     property FilterIndex: Integer default 1;
  93.     property InitialDir: string;
  94.     property Options: TOpenOptions default [ofHideReadOnly, ofEnableSizing];
  95.     property OptionsEx: TOpenOptionsEx default [];
  96.     property Title: string;
  97.     property OnCanClose: TCloseQueryEvent;
  98.     property OnFolderChange: TNotifyEvent;
  99.     property OnSelectionChange: TNotifyEvent;
  100.     property OnTypeChange: TNotifyEvent;
  101.     property OnIncludeItem: TIncludeItemEvent;
  102.   end;
  103.  
  104. { TSaveDialog }
  105.  
  106.   TSaveDialog = class(TOpenDialog)
  107.     function Execute: Boolean; override;
  108.   end;
  109.  
  110. { TColorDialog }
  111.  
  112.   TColorDialogOption = (cdFullOpen, cdPreventFullOpen, cdShowHelp,
  113.     cdSolidColor, cdAnyColor);
  114.   TColorDialogOptions = set of TColorDialogOption;
  115.  
  116.   TCustomColors = array[0..MaxCustomColors - 1] of Longint;
  117.  
  118.   TColorDialog = class(TCommonDialog)
  119.   public
  120.     constructor Create(AOwner: TComponent); override;
  121.     destructor Destroy; override;
  122.     function Execute: Boolean; override;
  123.   published
  124.     property Color: TColor default clBlack;
  125.     property Ctl3D default False;
  126.     property CustomColors: TStrings;
  127.     property Options: TColorDialogOptions default [];
  128.   end;
  129.  
  130. { TFontDialog }
  131.  
  132.   TFontDialogOption = (fdAnsiOnly, fdTrueTypeOnly, fdEffects,
  133.     fdFixedPitchOnly, fdForceFontExist, fdNoFaceSel, fdNoOEMFonts,
  134.     fdNoSimulations, fdNoSizeSel, fdNoStyleSel,  fdNoVectorFonts,
  135.     fdShowHelp, fdWysiwyg, fdLimitSize, fdScalableOnly, fdApplyButton);
  136.   TFontDialogOptions = set of TFontDialogOption;
  137.  
  138.   TFontDialogDevice = (fdScreen, fdPrinter, fdBoth);
  139.  
  140.   TFDApplyEvent = procedure(Sender: TObject; Wnd: HWND) of object;
  141.  
  142.   TFontDialog = class(TCommonDialog)
  143.   protected
  144.     procedure Apply(Wnd: HWND); dynamic;
  145.     procedure WndProc(var Message: TMessage); override;
  146.   public
  147.     constructor Create(AOwner: TComponent); override;
  148.     destructor Destroy; override;
  149.     function Execute: Boolean; override;
  150.   published
  151.     property Font: TFont;
  152.     property Device: TFontDialogDevice default fdScreen;
  153.     property MinFontSize: Integer;
  154.     property MaxFontSize: Integer;
  155.     property Options: TFontDialogOptions default [fdEffects];
  156.     property OnApply: TFDApplyEvent;
  157.   end;
  158.  
  159. { TPrinterSetupDialog }
  160.  
  161.   TPrinterSetupDialog = class(TCommonDialog)
  162.   public
  163.     function Execute: Boolean; override;
  164.   end;
  165.  
  166. { TPrintDialog }
  167.  
  168.   TPrintRange = (prAllPages, prSelection, prPageNums);
  169.   TPrintDialogOption = (poPrintToFile, poPageNums, poSelection, poWarning,
  170.     poHelp, poDisablePrintToFile);
  171.   TPrintDialogOptions = set of TPrintDialogOption;
  172.  
  173.   TPrintDialog = class(TCommonDialog)
  174.   public
  175.     function Execute: Boolean; override;
  176.   published
  177.     property Collate: Boolean default False;
  178.     property Copies: Integer default 0;
  179.     property FromPage: Integer default 0;
  180.     property MinPage: Integer default 0;
  181.     property MaxPage: Integer default 0;
  182.     property Options: TPrintDialogOptions default [];
  183.     property PrintToFile: Boolean default False;
  184.     property PrintRange: TPrintRange default prAllPages;
  185.     property ToPage: Integer default 0;
  186.   end;
  187.  
  188. { TFindDialog }
  189.  
  190.   TFindOption = (frDown, frFindNext, frHideMatchCase, frHideWholeWord,
  191.     frHideUpDown, frMatchCase, frDisableMatchCase, frDisableUpDown,
  192.     frDisableWholeWord, frReplace, frReplaceAll, frWholeWord, frShowHelp);
  193.   TFindOptions = set of TFindOption;
  194.  
  195.   TFindReplaceFunc = function(var FindReplace: TFindReplace): HWnd stdcall;
  196.  
  197.   TFindDialog = class(TCommonDialog)
  198.   protected
  199.     function MessageHook(var Msg: TMessage): Boolean; override;
  200.     procedure Find; dynamic;
  201.     procedure Replace; dynamic;
  202.   public
  203.     constructor Create(AOwner: TComponent); override;
  204.     destructor Destroy; override;
  205.     procedure CloseDialog;
  206.     function Execute: Boolean; override;
  207.     property Left: Integer;
  208.     property Position: TPoint;
  209.     property Top: Integer;
  210.   published
  211.     property FindText: string;
  212.     property Options: TFindOptions default [frDown];
  213.     property OnFind: TNotifyEvent;
  214.   end;
  215.  
  216. { TReplaceDialog }
  217.  
  218.   TReplaceDialog = class(TFindDialog)
  219.   public
  220.     constructor Create(AOwner: TComponent); override;
  221.   published
  222.     property ReplaceText;
  223.     property OnReplace;
  224.   end;
  225.  
  226. { Message dialog }
  227.  
  228. type
  229.   TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
  230.   TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
  231.     mbAll, mbNoToAll, mbYesToAll, mbHelp);
  232.   TMsgDlgButtons = set of TMsgDlgBtn;
  233.  
  234. const
  235.   mbYesNoCancel = [mbYes, mbNo, mbCancel];
  236.   mbYesAllNoAllCancel = [mbYes, mbYesToAll, mbNo, mbNoToAll, mbCancel];
  237.   mbOKCancel = [mbOK, mbCancel];
  238.   mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
  239.   mbAbortIgnore = [mbAbort, mbIgnore];
  240.  
  241. function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
  242.   Buttons: TMsgDlgButtons): TForm;
  243.  
  244. function MessageDlg(const Msg: string; DlgType: TMsgDlgType;
  245.   Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  246. function MessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
  247.   Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
  248. function MessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
  249.   Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer;
  250.   const HelpFileName: string): Integer;
  251.  
  252. procedure ShowMessage(const Msg: string);
  253. procedure ShowMessageFmt(const Msg: string; Params: array of const);
  254. procedure ShowMessagePos(const Msg: string; X, Y: Integer);
  255.  
  256. { Input dialog }
  257.  
  258. function InputBox(const ACaption, APrompt, ADefault: string): string;
  259. function InputQuery(const ACaption, APrompt: string;
  260.   var Value: string): Boolean;
  261.  
  262. function PromptForFileName(var AFileName: string; const AFilter: string = '';
  263.   const ADefaultExt: string = ''; const ATitle: string = '';
  264.   const AInitialDir: string = ''; SaveDialog: Boolean = False): Boolean;
  265.  
  266. { Win98 and Win2k will default to the "My Documents" folder if the InitialDir
  267.   property is empty and no files of the filtered type are contained in the
  268.   current directory. Set this flag to True to force TOpenDialog and descendents
  269.   to always open in the current directory when InitialDir is empty. (Same
  270.   behavior as setting InitialDir to '.') }
  271. var
  272.   ForceCurrentDirectory: Boolean = False;
  273.  
  274. implementation
  275.